from django import forms


from user.models import User


class LoginForm(forms.Form):
    username = forms.CharField(max_length=150, widget=forms.TextInput(attrs={
        'class': 'form-control', 'placeholder': '用户名'
    }))
    password = forms.CharField(widget=forms.PasswordInput(attrs={
        'class': 'form-control', 'placeholder': '密码'
    }))


class UserInfoForm(forms.ModelForm):
    class Meta:
        model = User
        fields = ['real_name', 'phone', 'email', 'sex']

    def __init__(self, *args, **kwargs):
        super(UserInfoForm, self).__init__(*args, **kwargs)

    def clean_email(self):
        email = self.cleaned_data.get('email')
        return email

class PasswordChangeForm(forms.Form):
    old_password = forms.CharField(
        label='原始密码',
        widget=forms.PasswordInput(attrs={'class': 'form-control', 'placeholder': '请输入账号原始密码'}),
    )
    new_password1 = forms.CharField(
        label='新密码',
        widget=forms.PasswordInput(attrs={'class': 'form-control', 'placeholder': '请输入新的密码'}),
    )
    new_password2 = forms.CharField(
        label='确认密码',
        widget=forms.PasswordInput(attrs={'class': 'form-control', 'placeholder': '请再次输入密码'}),
    )

class UserAddForm(forms.ModelForm):
    class Meta:
        model = User
        fields = ['username', 'password', 'real_name', 'phone', 'email', 'sex', 'status']
        widgets = {
            'password': forms.PasswordInput(attrs={'class': 'form-control', 'placeholder': '密码'}),
            'username': forms.TextInput(attrs={'class': 'form-control', 'placeholder': '用户名'}),
            'real_name': forms.TextInput(attrs={'class': 'form-control', 'placeholder': '真实姓名'}),
            'phone': forms.TextInput(attrs={'class': 'form-control', 'placeholder': '联系电话'}),
            'email': forms.EmailInput(attrs={'class': 'form-control', 'placeholder': '联系邮箱'}),
            'sex': forms.Select(attrs={'class': 'form-control'}, choices=[('男', '男'), ('女', '女')]),
            'status': forms.Select(attrs={'class': 'form-control'}, choices=[(0, '启用'), (1, '禁用')]),
        }